package com.kedacom.emptyproject.model.db

import android.arch.persistence.db.SupportSQLiteDatabase
import android.arch.persistence.room.Room
import android.arch.persistence.room.RoomDatabase
import android.arch.persistence.room.migration.Migration
import android.content.Context

//@Database(entities = arrayOf(), version = 1)
abstract class MainDatabase : RoomDatabase() {

    private val MIGRATION_1_2: Migration = object : Migration(1, 2) {

        override fun migrate(database: SupportSQLiteDatabase) {
            // Since we didn't alter the table, there's nothing else to do here.
        }
    }


    companion object {
        var mainDatabase: MainDatabase? = null


        @JvmStatic
        fun initDatabase(context: Context): MainDatabase {
            if (mainDatabase == null) {
                synchronized(MainDatabase::class.java) {
                    if (mainDatabase == null) {
                        mainDatabase = Room.databaseBuilder(
                            context.applicationContext,
                            MainDatabase::class.java, "main.db"
                        ) //                            .addMigrations(MIGRATION_1_2)
                            .build()
                    }
                }
            }
            return mainDatabase!!
        }
    }
}
